import 'package:flutter/material.dart';

class Waitingitem extends StatefulWidget {
  Waitingitem({super.key, required this.waitingItem});
  var waitingItem;

  @override
  State<Waitingitem> createState() => _WaitingitemState();
}

class _WaitingitemState extends State<Waitingitem> {
  // 订单信息
  var profileInfo = {};
  // 订单状态
  var orderStatus = {'1': '待提货', '2': '在途', '3': '改派', '4': '已交付', '5': '已作废'};
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    profileInfo = widget.waitingItem;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: MediaQuery.of(context).size.width,
      height: 200,
      margin: EdgeInsets.all(10),
      padding: EdgeInsets.all(10),
      decoration: BoxDecoration(
        color: Colors.white,
        border: Border(),
        borderRadius: BorderRadius.circular(10),
      ),
      child: Column(
        children: [
          //  ---------------- 头部 任务编号/ 状态 ----------------
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text('任务编号: ' + '${profileInfo['id']}'),
              Container(
                decoration: BoxDecoration(
                  border: Border.all(color: Colors.orange),
                  borderRadius: BorderRadius.circular(5),
                ),
                child: Text(
                  '${orderStatus['${profileInfo['status']}']}',
                  style: TextStyle(color: Colors.orange),
                ),
              ),
            ],
          ),
          //  ---------------- 中间 发货起始地点信息 ----------------
          Expanded(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                // ------------------- 起点--------------
                Row(
                  children: [
                    Container(
                      width: 20,
                      height: 20,
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                        border: Border.all(),
                        borderRadius: BorderRadius.circular(100),
                        color: Colors.black,
                      ),
                      child: Text(
                        '起',
                        style: TextStyle(color: Colors.white),
                        textAlign: TextAlign.center,
                      ),
                    ),
                    SizedBox(width: 10),
                    Container(
                      width: 250,
                      height: 40,
                      child: Text(
                        '${profileInfo['startAddress']}',
                        style: TextStyle(color: Colors.grey),
                        maxLines: 2,
                        overflow: TextOverflow.ellipsis,
                      ),
                    ),
                  ],
                ),
                // ------------------- 起点--------------
                Row(
                  children: [
                    Container(
                      width: 20,
                      height: 20,
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                        border: Border.all(),
                        borderRadius: BorderRadius.circular(100),
                        color: const Color.fromARGB(255, 226, 38, 38),
                      ),
                      child: Text(
                        '止',
                        style: TextStyle(color: Colors.white),
                        textAlign: TextAlign.center,
                      ),
                    ),
                    SizedBox(width: 10),
                    Container(
                      width: 250,
                      height: 40,
                      child: Text(
                        '${profileInfo['endAddress']}',
                        style: TextStyle(color: Colors.grey),
                        maxLines: 2,
                        overflow: TextOverflow.ellipsis,
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),
          SizedBox(height: 10),
          //  ---------------- 底部 任务编号/ 状态 ----------------
          Container(
            height: 40,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Container(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text('提交时间'),
                      Text('${profileInfo['planArrivalTime']}'),
                    ],
                  ),
                ),
                ElevatedButton(
                  onPressed: () {},
                  style: ElevatedButton.styleFrom(
                    backgroundColor:
                        profileInfo['enablePickUp']
                            ? Colors.red
                            : Colors.grey, // 设置背景色
                  ),
                  child: Container(
                    width: 40,
                    height: 30,
                    alignment: Alignment.center,
                    child: Text('提货'),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
